import { RouterMount, createRouter } from 'uni-simple-router'
// import store from './store'

// eslint-disable-next-line no-undef
console.log('ROUTES----------', ROUTES)

const router = createRouter({
  platform: process.env.VUE_APP_PLATFORM,
  // eslint-disable-next-line no-undef
  routes: [...ROUTES],
  beforeProxyHooks: {
    onLoad(options, next) {
      next([router.currentRoute.query])
    },
    onShow([options], next) {
      const args = options || router.currentRoute.query
      next([args])
    }
  }
})
// 全局路由前置守卫
router.beforeEach((to, from, next) => {
  console.log('跳转开始', to.name)
  next()

  /* if (to.name != 'login') {
    const token = uni.getStorageSync('token')
    console.log('token', token)
    if (token) {
      next()
    } else {
      next({
        name: 'login',
        NAVTYPE: 'replaceAll'
      })
    }
  } else {
    next()
  } */
})
// 全局路由后置守卫
router.afterEach((to, from) => {
  console.log('跳转结束')
})

export {
  router,
  RouterMount
}
